/*
 * @Description:
 * @Version: 2.0
 * @Autor: Seven
 * @Date: 2023-10-16 10:08:13
 * @LastEditors: Seven
 * @LastEditTime: 2023-10-26 08:59:49
 */
/*
 * @Description:
 * @Version: 2.0
 * @Autor: Seven
 * @Date: 2023-10-16 10:08:13
 * @LastEditors: Seven
 * @LastEditTime: 2023-10-16 14:17:06
 */
import axios from "axios";
import BASE_URL, { TIMEOUT } from "./config";
class HYRequest {
  constructor(baseURL, timeout) {
    this.instance = axios.create({
      baseURL,
      timeout,
    });

    this.instance.interceptors.response.use(
      (res) => {
        return res.data;
      },
      (err) => {
        return err;
      }
    );
  }

  request(config) {
    return this.instance.request(config);
  }

  get(config) {
    return this.request({ ...config, method: "get" });
  }

  post(config) {
    return this.request({ ...config, method: "post" });
  }
  delete(config) {
    return this.request({ ...config, method: "delete" });
  }
}

const Request = new HYRequest(BASE_URL, TIMEOUT);
export default Request;
